package com.niiwoo.civet.account.service.local.openAccount2.lanmao;

import com.niiwoo.civet.account.dao.entity.GroupAccountCorrelateOrder;
import com.niiwoo.civet.account.service.local.openAccount2.dto.CreateRequest;
import com.niiwoo.civet.account.service.local.openAccount2.type.GroupTypeable;
import com.niiwoo.tripod.lanmao.component.LanMaoGatewayService;
import com.niiwoo.tripod.lanmao.enums.GroupAccountCorrelateTypeEnum;
import com.niiwoo.tripod.lanmao.request.GroupAccountCorrelateRequest;
import com.niiwoo.tripod.lanmao.response.LanMaoGatewayDTO;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GroupLanMaoHandler implements OpenAccountLanMaoOperation<GroupAccountCorrelateOrder>, GroupTypeable {

    @Autowired
    LanMaoGatewayService lanMaoGatewayService;

    @Override
    public LanMaoGatewayDTO generateLanMaoGatewayDTO(CreateRequest request, GroupAccountCorrelateOrder order) {
        GroupAccountCorrelateRequest groupAccountCorrelateRequest = new GroupAccountCorrelateRequest();
        groupAccountCorrelateRequest.setRequestNo(order.getRequestNo());
        groupAccountCorrelateRequest.setPlatformUserNo(order.getAccountNo());
        groupAccountCorrelateRequest.setGroupAccountNo(order.getGroupAccountNo());
        groupAccountCorrelateRequest.setType(GroupAccountCorrelateTypeEnum.enumOf(order.getCorrelateType())); // 关联方式
        groupAccountCorrelateRequest.setUserRole(request.getRole());
        groupAccountCorrelateRequest.setAuthList(order.getAuthList());
        groupAccountCorrelateRequest.setTimestamp(new Date());
        groupAccountCorrelateRequest.setNiiwooRedirectUrl(request.getRedirectUrl());
        groupAccountCorrelateRequest.setFailTime(LanMaoHelper.getFixFailTime());
        groupAccountCorrelateRequest.setAmount(LanMaoHelper.getFixLimitAmount());
        return lanMaoGatewayService.groupAccountCorrelate(groupAccountCorrelateRequest);
    }

}
